package com.javawork.juc.synchronize;

/**
 * 锁粗化：假如方法中首 尾相接，前后相邻的都是同一个锁对象，那JIT编译器就会把这几个synchronized块合并成一个大划加粗加大范围，一次申请锁使用即可，避免次次的申请和释放锁，提升了性能
 * @author zhangxiaolu
 * @since 2023-02-16 0:14
 */
public class LockBigDemo {

    static Object objectLock = new Object();

    public static void main(String[] args) {
        new Thread(() -> {
            synchronized (objectLock) {
                System.out.println("111111");
            }
            synchronized (objectLock) {
                System.out.println("222222");
            }
            synchronized (objectLock) {
                System.out.println("333333");
            }
            synchronized (objectLock) {
                System.out.println("444444");
            }
            //上下等价
            synchronized (objectLock) {
                System.out.println("111111");
                System.out.println("222222");
                System.out.println("333333");
                System.out.println("444444");
            }
        }, "t1").start();
    }
}
